package com.ljt.yupictureddd.domain.user.valueobject;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum UserRoleEnums {
    USER("用户","user"),
    ADMIN("管理员","admin");

    private final String text;

    private final String value;

    UserRoleEnums(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举
     * @param value
     * @return
     */
    public static UserRoleEnums getEnumByValue(String value){
        if (ObjUtil.isEmpty(value)){
            return null;
        }
        UserRoleEnums userRoleEnums = Arrays.stream(UserRoleEnums.values())
                .filter(u -> u.getValue().equalsIgnoreCase(value))
                .findFirst()
                .get();
        return userRoleEnums;
    }
}
